﻿using B.S.BaseData.Api.Write.Applicantion.Command.OrderCommand;
using B.S.BaseData.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace WorkOrder.API.Write.Controllers
{
    /// <summary>
    /// 订单管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class OrderController : ControllerBase
    {
        private readonly IMediator _mediator;

        public OrderController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 删除问诊单
        /// </summary>
        /// <param name="orderNumber">订单编号</param>
        /// <returns>删除结果</returns>
        [HttpDelete]
        public Task<APIResult<bool>> DeleteConsultationOrder(string orderNumber)
        {
            var command = new DeleteConsultationOrderCommand { OrderNumber = orderNumber };
            return _mediator.Send(command);
        }

        /// <summary>
        /// 批量删除问诊单
        /// </summary>
        /// <param name="command">批量删除命令</param>
        /// <returns>删除结果</returns>
        [HttpPost]
        public Task<APIResult<bool>> BatchDeleteConsultationOrder([FromBody] BatchDeleteConsultationOrderCommand command)
        {
            return _mediator.Send(command);
        }

        /// <summary>
        /// 删除处方流转订单
        /// </summary>
        /// <param name="orderNumber">订单编号</param>
        /// <returns>删除结果</returns>
        [HttpDelete]
        public Task<APIResult<bool>> DeletePrescriptionOrder(string orderNumber)
        {
            var command = new DeletePrescriptionOrderCommand { OrderNumber = orderNumber };
            return _mediator.Send(command);
        }

        /// <summary>
        /// 批量删除处方流转订单
        /// </summary>
        /// <param name="command">批量删除命令</param>
        /// <returns>删除结果</returns>
        [HttpPost]
        public Task<APIResult<bool>> BatchDeletePrescriptionOrder([FromBody] BatchDeletePrescriptionOrderCommand command)
        {
            return _mediator.Send(command);
        }

        /// <summary>
        /// 核准发药
        /// </summary>
        /// <param name="orderNumber">订单编号</param>
        /// <returns>核准结果</returns> 
        [HttpGet]
        public Task<APIResult<bool>> ApproveDispensing([FromQuery]string orderNumber)
        {
            var command = new ApproveDispensingCommand { OrderNumber = orderNumber };
            return _mediator.Send(command);
        }

        /// <summary>
        /// 更新处方流转订单
        /// </summary>
        /// <param name="command">更新命令</param>
        /// <returns>更新结果</returns>
        [HttpPut]
        public Task<APIResult<bool>> UpdatePrescriptionOrder([FromBody] UpdatePrescriptionOrderCommand command)
        {
            return _mediator.Send(command);
        }

        /// <summary>
        /// 处理退款申请
        /// </summary>
        /// <param name="command">处理命令</param>
        /// <returns>处理结果</returns>
        [HttpPost]
        public Task<APIResult<bool>> ProcessRefundApplication([FromBody] ProcessRefundApplicationCommand command)
        {
            return _mediator.Send(command);
        }

        /// <summary>
        /// 药品订单发货
        /// </summary>  
        /// <param name="command">发货命令</param>
        /// <returns>发货结果</returns>
        [HttpPost]
        public Task<APIResult<bool>> ShipMedicineOrder([FromBody] ShipMedicineOrderCommand command)
        {
            return _mediator.Send(command);
        }   

        /// <summary>
        /// 确认收货
        /// </summary>
        /// <param name="command">确认收货命令</param>
        /// <returns>确认结果</returns>  
        [HttpPost]
        public Task<APIResult<bool>> ConfirmReceipt([FromBody] ConfirmReceiptCommand command)
        {   
            return _mediator.Send(command);  
        }

    }
}
